package com.louis.mango.admin.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {

    /**
     * 从上往下依次为
     * 允许跨域访问的路径
     * 允许跨域访问的资源
     * 允许请求的方法
     * 允许的时间健哥
     * 允许的头部设置
     * 是否发送cookie
     * @param registry
     */
    @Override
    public void addCorsMappings( CorsRegistry registry ){
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("POST","PUT","GET","OPTIONS","DELETE")
                .maxAge(16800)
                .allowedHeaders("*")
                .allowCredentials(true);
    }

}
